//
//  CommentCell.swift
//  Drop
//
//  Created by zhuxuhong on 2018/3/17.
//  Copyright © 2018年 zhuxuhong. All rights reserved.
//

import UIKit

class CommentCell: UITableViewCell {

    @IBOutlet weak var contentLabelBottomConstraint: NSLayoutConstraint!
    @IBOutlet weak var actionBtnHeightConstraint: NSLayoutConstraint!
    
    @IBOutlet weak var wrapper: UIView!
    @IBOutlet weak var authorAvatarIV: UIImageView!
    @IBOutlet weak var contentLabel: UILabel!
    @IBOutlet weak var likeBtn: UIButton!
    @IBOutlet weak var commentBtn: UIButton!
    
    var comment: Comment!{
        didSet{
            setupData()
//            updateLayoutForExpanded()
        }
    }
    
    override func awakeFromNib() {
        super.awakeFromNib()
        
    }
    
    fileprivate func setupData() {
        contentLabel.attributedText = comment.attributedContent
        
        let likeIcon = comment.isLiked
            ? "appreciate_fill"
            : "appreciate"
        likeBtn?.setTitle("\(comment.likes)", for: .normal)
        likeBtn?.setImage(UIImage.named(likeIcon), for: .normal)
    }

    fileprivate func updateLayoutForExpanded(){
        let isExpanded = comment.isExpanded
        contentLabelBottomConstraint.constant = isExpanded ? 10 : 0
        actionBtnHeightConstraint.constant = isExpanded ? 24 : 0
        likeBtn.isHidden = !isExpanded
        commentBtn.isHidden = !isExpanded
    }
    
}
